import { IWorld } from '../common/world.interface';
import { System } from './system';

export class StatsSystem extends System {
  #elapsed: number = 0;
  #updates: number = 0;

  #logCb: (message: string) => void;

  constructor(logCb: (message: string) => void) {
    super();

    this.#logCb = logCb;
  }

  onUpdate(world: IWorld, dt: number) {
    if (this.#elapsed < 1) {
      this.#elapsed += dt;
      this.#updates += 1;
    } else {
      this.#logCb(`Updates per second: ${this.#updates}`);

      this.#elapsed = 0;
      this.#updates = 0;
    }
  }
}
